﻿@model QAS.Nekorama.Models.Answer

<script src="~/Scripts/jquery-1.8.2.min.js"> </script>
<script src="~/Scripts/jquery.validate.min.js"> </script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"> </script>

@using (Html.BeginForm("Answer", "Question", FormMethod.Post, new {@id = "postAnswerForm"}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Answer</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.QuestionID)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.QuestionID)
            @Html.ValidationMessageFor(model => model.QuestionID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Content)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Content)
            @Html.ValidationMessageFor(model => model.Content)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.VoteCount)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.VoteCount)
            @Html.ValidationMessageFor(model => model.VoteCount)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SpamCount)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SpamCount)
            @Html.ValidationMessageFor(model => model.SpamCount)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsSpam)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsSpam)
            @Html.ValidationMessageFor(model => model.IsSpam)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsAccepted)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsAccepted)
            @Html.ValidationMessageFor(model => model.IsAccepted)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsDeleted)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsDeleted)
            @Html.ValidationMessageFor(model => model.IsDeleted)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EditReason)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EditReason)
            @Html.ValidationMessageFor(model => model.EditReason)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.VoteUpUserList)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.VoteUpUserList)
            @Html.ValidationMessageFor(model => model.VoteUpUserList)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.VoteDownUserList)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.VoteDownUserList)
            @Html.ValidationMessageFor(model => model.VoteDownUserList)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SpamMarkUserList)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SpamMarkUserList)
            @Html.ValidationMessageFor(model => model.SpamMarkUserList)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CreatedDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.CreatedDate)
            @Html.ValidationMessageFor(model => model.CreatedDate)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CreatedUser)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.CreatedUser)
            @Html.ValidationMessageFor(model => model.CreatedUser)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.LastModifiedDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastModifiedDate)
            @Html.ValidationMessageFor(model => model.LastModifiedDate)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ModifiedUser)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ModifiedUser)
            @Html.ValidationMessageFor(model => model.ModifiedUser)
        </div>

        <div style="text-align: right;">
            @Html.ActionLink(QAS_Nekorama.POST_ANSWER, null, null, new {@class = "answer-btn", @onclick = "postAnswer(event);"})
        </div>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script> function postAnswer(event) {
    $('#postAnswerForm').submit();
    if ($("#answer-content").val().trim().length < 30) {
        $(".jqte_editor").validationEngine('showPrompt', '@Messages.ANSWER_CONTENT_LENGTH', 'error', 'centerRight', true);
        event.preventDefault();
        return false;
    } else {
        $(".jqte").removeClass("validate[[required],min[30]]");
        $(".jqte").validationEngine('hideAll');
                                    @* var newans = new Object();
                    newans.QuestionID = '@Model.Question.QuestionID';
                    newans.VoteCount = 0;

                    newans.createduser = '@currentuser';
                    newans.isAccepted = false;
                    newans.spamcount = 0;
                    newans.isdeleted = false;
                    newans.isspam = false;
                    newans.Content = $('#answer-content').val();
                    $('#answer-content').val("");
                    newans.CreatedDate = '@DateTime.Now';
                    //alert(newans.Content);
                    $.ajax({
                        type: 'POST',
                        url: '/Question/Answer',
                        async: false,
                        data: JSON.stringify(newans),
                        contentType: 'application/json; charset=utf-8',
                        cash: false,
                        success: null,
                        completed: location.reload()//alert("post new answer success!")
                    });*@
        $('#postAnswerForm').submit();
    }

} </script>